package com.zhoun.service.impl;

import com.zhoun.common.ServerResponse;
import com.zhoun.dao.UserMapper;
import com.zhoun.pojo.User;
import com.zhoun.service.UserService;
import com.zhoun.util.Md5Util;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;
    public ServerResponse login(String username,String password){
        int resultCount = userMapper.checkUsername(username);
        if (resultCount == 0){
            return ServerResponse.createByErrorMessage("用户名不存在，请重新输入");
        }
        String md5Password = Md5Util.md5(password,Md5Util.SALT);
        User user = userMapper.selectByUsernameAndPassword(username,md5Password);
        if (user == null){
            return ServerResponse.createByErrorMessage("密码错误,请重新输入");
        }
        user.setPassword(StringUtils.EMPTY);
        return ServerResponse.createBySuccess(user);
    }





}
